package suanfa;

import java.util.LinkedList;
import java.util.Queue;

public class test8 {
    private Queue<Integer> q1=new LinkedList<>();
    private Queue<Integer> q2=new LinkedList<>();
    private int top;
    /** Initialize your data structure here. */
    public void MyStack() {

    }

    /** Push element x onto stack. */
    public void push(int x) {
        q1.add(x);
        top=x;
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        int popzhi;
        while (q1.size()>1){
            top=q1.remove(); //最后一个remove的就是栈的第二个元素 即为pop后的栈顶元素
            q2.add(top);
        }
       popzhi= q1.remove();
        Queue<Integer> t=new LinkedList<>();
        t=q1;
        q1=q2;
        q2=t;
        return popzhi;
    }

    /** Get the top element. */
    public int top() {
        return top;
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        if (q1.size()==0)
            return true;
        else
            return  false;
    }
}
